import time

from selenium.webdriver.common.by import By

from common.Untils import QESDriver

class MyPractice:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://8.155.1.153:8081/exercise"
        self.driver = QESDriver.driver
        self.driver.get(self.url)

    def GetMyPractice(self):
        # 查找页面元素并截图
        title1 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[1]/div/div[1]/div').text
        assert title1 == "我的练习"
        title2 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[1]').text
        assert title2 == "练习名称"
        title3 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[2]').text
        assert title3 == "练习进度"
        title4 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[3]').text
        assert title4 == "练习类型"
        title5 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[4]').text
        assert title5 == "状态"
        title6 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[5]').text
        assert title6 == "创建时间"
        title7 = self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/thead/tr/th[6]').text
        assert title7 == "操作"
        QESDriver.GetScreenShot()
        ################################################################################

    def MathExercise(self):
        # 点击“数学”
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div').click()
        # 查找输入框并输入1
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("1")
        # 查找“查询”并点击然后截图
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # 查找“重置”并点击
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        # 查找“开始练习”并点击
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr[1]/td[3]/div/div/a').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # 查找页面元素
        # title1 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div[2]/div/div[2]/div/div/div[2]/div[1]/div/div/div').text
        # assert title1 == "顺序练习"
        # title2 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div[2]/div/div[2]/div/div/div[2]/div[2]/div/div/div').text
        # assert title2 == "随机练习"
        # title3 = self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div[2]/div/div[2]/div/div/div[2]/div[3]/div/div/div').text
        # assert title3 == "错题练习"

    # 顺序练习
    # def PracticeInSequence(self):
    #     # 点击“顺序练习”并截图
    #     self.driver.find_element(By.XPATH,'/html/body/div[5]/div/div[2]/div/div[2]/div/div/div[2]/div[1]/div/div/div').click()
    #     # 点击“下一页”
    #     self.driver.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div/div[5]/div/div[1]/button').click()
    #     # 点击“答对自动跳转下一页”
    #     self.driver.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div/div[5]/div/div[4]/button').click()
    #     # 点击最后一题并点击“结束练习”
    #     self.driver.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div/div[6]/div[2]/div[13]').click()
    #     self.driver.find_element(By.XPATH, '//*[@id="root"]/div[2]/div/div/div[5]/div[2]/div[2]/button/div').click()
    #     time.sleep(0.5)
    #     QESDriver.GetScreenShot()

    def ChineseExercises(self):
        # 点击“语文”
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[1]/div[1]/div[1]/div/div[3]').click()
        # 查找输入框并输入1
        self.driver.find_element(By.XPATH, '//*[@id="name"]').send_keys("1")
        # 查找“查询”并点击然后截图
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[2]/button').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()
        # 查找“重置”并点击
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[1]/form/div/div[2]/div/div/div[2]/div/div/div/div/div/div[1]/button').click()
        # 查找“开始练习”并点击
        self.driver.find_element(By.XPATH,'//*[@id="sk-layout"]/div/div/section/div[2]/main/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div/div/div/table/tbody/tr/td[3]/div/div/a').click()
        time.sleep(0.5)
        QESDriver.GetScreenShot()

